﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Xml;
public partial class XML_ReadFromXML : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        GetData();
        BindColumn();
    }
    private void BindColumn()
    {
        ListItem lItem = new ListItem();
        string path = Server.MapPath("~/XML/");
        string[] filename = Directory.GetFiles(path, "Log_*.xml", System.IO.SearchOption.TopDirectoryOnly);
        if (filename.Length > 0)
        {
            foreach (string file in filename)
            {
                ds.ReadXml(file);
            }
            for (int i = 1; i < ds.Tables[0].Columns.Count; i++)
            {
                DropDownList1.Items.Insert(0, new ListItem(ds.Tables[0].Columns[i].ToString(), i.ToString()));
            }                       
        }
    }
    private void GetData()
    {
        DataSet ds = new DataSet();
        string path = Server.MapPath("~/XML/");
        string[] filename = Directory.GetFiles(path, "Log_*.xml", System.IO.SearchOption.TopDirectoryOnly);
        if (filename.Length > 0)
        {
            foreach (string file in filename)
            {
                ds.ReadXml(file);
                grdxml.DataSource = ds.Tables[0];
                grdxml.DataBind();
            }
        }   
    }
}